//
//  ChangeViewController.m
//  carSecretary
//
//  Created by huangliru on 14-9-4.
//  Copyright (c) 2014年 huangliru. All rights reserved.
//

#import "ChangeViewController.h"
#import "LoginViewController.h"
@interface ChangeViewController ()

@end

@implementation ChangeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIControl *control = [[UIControl alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    
    //创建一个导航栏
    UINavigationBar *bar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 18, 320, 44)];
    //创建一个导航栏集合
    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:nil];
    //创建一个左边按钮
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:self action:@selector(backButton)];
    //设置导航栏内容
    [navigationItem setTitle:@"设置新密码"];
    //把导航栏集合添加入导航栏中，设置动画关闭
    [bar pushNavigationItem:navigationItem animated:NO];
    //把左按钮添加入导航栏集合中
    [navigationItem setLeftBarButtonItem:leftButton];
    bar.backgroundColor = [UIColor grayColor];
    [control addSubview:bar];
    
    UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(20, 139, 110, 40)];
    name.text = @"账       号：";
    name.tintColor = [UIColor blackColor];
    [control addSubview:name];
    UILabel *pswd = [[UILabel alloc]initWithFrame:CGRectMake(20, 223, 110, 40)];
    pswd.text = @"新  密  码：";
    pswd.tintColor = [UIColor blackColor];
    [control addSubview:pswd];
    UILabel *sure = [[UILabel alloc]initWithFrame:CGRectMake(20, 306, 110, 40)];
    sure.text = @"确认密码：";
    sure.tintColor = [UIColor blackColor];
    [control addSubview:sure];
    
    // 初始化账号输入
    self.userNameText = [[UITextField alloc]initWithFrame:CGRectMake(126 , 144, 175, 30)];
    //让字体大小自适应控件的区域
    [self.userNameText setBorderStyle:UITextBorderStyleRoundedRect];
    [self.userNameText  setAdjustsFontSizeToFitWidth:YES];
    self.userNameText.placeholder = @"请输入您的用户名";
    //设置委托对象
    self.userNameText.delegate = self;
    //添加到本视图
    [control addSubview: self.userNameText];
    
    
    self.pswdText = [[UITextField alloc]initWithFrame:CGRectMake(126, 228, 175, 30)];
    //让字体大小自适应控件的区域
    [self.pswdText setBorderStyle:UITextBorderStyleRoundedRect];
    [self.pswdText  setAdjustsFontSizeToFitWidth:YES];
    self.pswdText.placeholder = @"请输入您的密码";
    self.pswdText.secureTextEntry = YES;
    //设置委托对象
    self.self.pswdText.delegate = self;
    //添加到本视图
    [control addSubview: self.pswdText];
    
    self.surePswd = [[UITextField alloc]initWithFrame:CGRectMake(126, 311, 175, 30)];
    //让字体大小自适应控件的区域
    [self.surePswd setBorderStyle:UITextBorderStyleRoundedRect];
    [self.surePswd  setAdjustsFontSizeToFitWidth:YES];
    self.surePswd.placeholder = @"请再次输入您的密码";
    self.surePswd.secureTextEntry = YES;
    //设置委托对象
    self.surePswd.delegate = self;
    //添加到本视图
    [control addSubview: self.surePswd];
    
    //提交按钮
    self.submitButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.submitButton.frame = CGRectMake(79, 413, 162, 50);
    self.submitButton.tintColor = [UIColor blackColor];
    [self.submitButton setTitle:@"提交" forState:UIControlStateNormal];
    [self.submitButton setBackgroundImage:[UIImage imageNamed:@"213.png"] forState:UIControlStateNormal];
    [self.submitButton addTarget:self action:@selector(submitButtonPress) forControlEvents:UIControlEventTouchUpInside];
    [control addSubview:self.submitButton];
    
    
    
    
    [control addTarget:self action:@selector(textFieldShouldReturn:) forControlEvents:UIControlEventTouchDown];
    self.view = control;
}
// 提交按钮
-(void)submitButtonPress
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"修改密码成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
    alert.delegate = self;
}
// 导航栏返回按钮
-(void)backButton
{
    [self dismissViewControllerAnimated:NO completion:nil];
}
//实现textfielddelegate方法
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    [UIView  beginAnimations:@"aa" context:nil];
    [UIView setAnimationDuration:0.3];
    if ([textField tag] == 12)
    {
        CGRect frame = self.view.frame;
        frame.origin.y -= 50;
        self.view.frame = frame;
    }
    [UIView commitAnimations];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [UIView beginAnimations:@"aa" context:nil];
    self.view.frame = CGRectMake(0, 0, 320, 560);
    [UIView setAnimationDuration:0.3];
    [UIView commitAnimations];
    
    
    [self.userNameText resignFirstResponder];
    [self.pswdText resignFirstResponder];
    [self.surePswd resignFirstResponder];
    return YES;
}
//AlertView已经消失时执行的事件

#pragma mark -UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    LoginViewController *loginVC = [[LoginViewController alloc]init];
    [self presentViewController:loginVC animated:NO completion:nil];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
